<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" id="file">
    <img src="" id="img" alt="">
    <script>
       /*  var file=document.querySelector('#file')
        var img=document.querySelector('#img')
        file.onchange=function(){
            img.src=URL.createObjectURL(this.files[0])
        } */
        // 思路2
        var fileReader=new FileReader()
        fileReader.readAsDataURL(this.files[0])
        fileReader.onload=function(e){
            img.src=e.target.result
        }
    </script>
</body>
</html>